﻿Imports MICROFORMA.BEL
Imports MICROFORMA.BLL

Public Class frmAddListVariables

    Public strListVariables As String
    Public strListIndices As String
    Public IdTipoDocumental As Integer
    Dim flag As Boolean

    Sub New(Optional ByVal _flag As Boolean = False)
        flag = _flag
        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

    End Sub

    Private Sub frmAddListVariables_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim indicesBL As New IndicesBL
        Dim table As DataTable = indicesBL.List(IdTipoDocumental)

        If flag Then
            LoadListAllIndices(table)
        Else
            LoadList(table)
        End If

        If table.Rows.Count = 0 Then
            btnAdd.Enabled = False
        End If

    End Sub

    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        strListVariables = ""
        Me.Close()
    End Sub

    Private Sub LoadListAllIndices(ByVal _table As DataTable)

        'If Not flag Then
        '    For i As Int16 = 0 To table.Rows.Count - 1
        '        'lstListVar.Items.Add(table.Rows(i).Item("Nombre"))
        '        lstListVar.Items.Insert(CInt(table.Rows(i).Item("IdIndice")) - 1, table.Rows(i).Item("Nombre"))
        '    Next
        'End If

        'If flag Then
        For i As Int16 = 0 To _table.Rows.Count - 1
            lstListVar.Items.Add(_table.Rows(i).Item("Nombre"))
            'lstListVar.Items.Insert(table.Rows(i).Item("IdIndice"), table.Rows(i).Item("Nombre"))
        Next
        lstListVar.Items.Add("Nombre de usuario")
        lstListVar.Items.Add("Grupo de Usuario")
        lstListVar.Items.Add("Dominio")
        lstListVar.Items.Add("Fecha del sistema")
        lstListVar.Items.Add("Hora del Sistema")
        lstListVar.Items.Add("Direccion IP de la PC Cliente")
        lstListVar.Items.Add("OTRO POR DEFINIR")
        'End If

    End Sub

    Private Sub LoadList(ByVal _table As DataTable)
        lstListVar.ValueMember = "IdIndice"
        lstListVar.DisplayMember = "Nombre"
        lstListVar.DataSource = _table
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        If lstListVar.SelectedItems.Count > 0 Then
            If flag Then
                For i As Int16 = 0 To lstListVar.SelectedItems.Count - 1
                    strListVariables += lstListVar.SelectedItems(i).ToString & ","
                Next
            Else
                For Each row As DataRowView In lstListVar.SelectedItems
                    strListVariables += row.Item("Nombre").ToString & ","
                    strListIndices += row.Item("IdIndice").ToString & ","
                Next
            End If

            Me.Close()
        Else
            Me.Close()
        End If
    End Sub
End Class